package cn.andrewlu.weexshell.utils;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import java.io.InputStream;

/**
 * Created by andrewlu on 2017/6/12.
 */

public class AssetsTool {
    public final static Drawable getDrawable(Context context, String assetsPath) {
        AssetManager assetManager = context.getAssets();

        try {
            if (assetsPath.startsWith("assets://")) {
                assetsPath = assetsPath.substring(9);
            }
            InputStream in = assetManager.open(assetsPath);
            Drawable drawable = new BitmapDrawable(context.getResources(), in);
            return drawable;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
